<html>
<head><meta charset="utf-8"><title>How to get inferred type from assert_eq! macro · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html">How to get inferred type from assert_eq! macro</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231544677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/231544677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Siva Renganathan <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#231544677">(Mar 23 2021 at 21:12)</a>:</h4>
<p>I'd like some help on ways to get the inferred type from the assert_eq! macro, I'm particularly interested in finding whether the compared expressions are literals or const, First time posting on this forum, please redirect me to the right place just in case this is not the place for this question</p>



<a name="231545280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/231545280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Siva Renganathan <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#231545280">(Mar 23 2021 at 21:16)</a>:</h4>
<div class="codehilite" data-code-language="left"><pre><span></span><code>    hir_id: HirId {
        owner: DefId(0:14 ~ float_cmp[317d]::main),
        local_id: 457,
    },
    kind: Unary(
        Deref,
        Expr {
            hir_id: HirId {
                owner: DefId(0:14 ~ float_cmp[317d]::main),
                local_id: 456,
            },
            kind: Path(
                Resolved(
                    None,
                    Path {
                        span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:23: 39:31 (#7),
                        res: Local(
                            HirId {
                                owner: DefId(0:14 ~ float_cmp[317d]::main),
                                local_id: 451,
                            },
                        ),
                        segments: [
                            PathSegment {
                                ident: left_val#7,
                                hir_id: Some(
                                    HirId {
                                        owner: DefId(0:14 ~ float_cmp[317d]::main),
                                        local_id: 455,
                                    },
                                ),
                                res: Some(
                                    Local(
                                        HirId {
                                            owner: DefId(0:14 ~ float_cmp[317d]::main),
                                            local_id: 451,
                                        },
                                    ),
                                ),
                                args: None,
                                infer_args: true,
                            },
                        ],
                    },
                ),
            ),
            attrs: ThinVec(
                None,
            ),
            span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:23: 39:31 (#7),
        },
    ),
    attrs: ThinVec(
        None,
    ),
    span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:22: 39:31 (#7),
}
[clippy_lints/src/misc.rs:728] right = Expr {
    hir_id: HirId {
        owner: DefId(0:14 ~ float_cmp[317d]::main),
        local_id: 460,
    },
    kind: Unary(
        Deref,
        Expr {
            hir_id: HirId {
                owner: DefId(0:14 ~ float_cmp[317d]::main),
                local_id: 459,
            },
            kind: Path(
                Resolved(
                    None,
                    Path {
                        span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:36: 39:45 (#7),
                        res: Local(
                            HirId {
                                owner: DefId(0:14 ~ float_cmp[317d]::main),
                                local_id: 452,
                            },
                        ),
                        segments: [
                            PathSegment {
                                ident: right_val#7,
                                hir_id: Some(
                                    HirId {
                                        owner: DefId(0:14 ~ float_cmp[317d]::main),
                                        local_id: 458,
                                    },
                                ),
                                res: Some(
                                    Local(
                                        HirId {
                                            owner: DefId(0:14 ~ float_cmp[317d]::main),
                                            local_id: 452,
                                        },
                                    ),
                                ),
                                args: None,
                                infer_args: true,
                            },
                        ],
                    },
                ),
            ),
            attrs: ThinVec(
                None,
            ),
            span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:36: 39:45 (#7),
        },
    ),
    attrs: ThinVec(
        None,
    ),
    span: /Users/srenganathan/.rustup/toolchains/nightly-2021-02-25-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/macros/mod.rs:39:35: 39:45 (#7),
}
</code></pre></div>



<a name="231545308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/231545308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Siva Renganathan <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#231545308">(Mar 23 2021 at 21:17)</a>:</h4>
<p>This is what I see in the HIR expression object, Is there some way to get type inference from this</p>



<a name="233196218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/233196218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#233196218">(Apr 05 2021 at 16:33)</a>:</h4>
<p><span class="user-mention" data-user-id="395250">@Siva Renganathan</span> Can you elaborate on your use case? Are you writing a lint, or some tool that interacts with the compiler?</p>



<a name="233452525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/233452525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Siva Renganathan <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#233452525">(Apr 07 2021 at 08:44)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span>  Yes I'm updating a lint, I was working on this issue on clippy, <a href="https://github.com/rust-lang/rust-clippy/issues/6817">https://github.com/rust-lang/rust-clippy/issues/6817</a>, for the same I have to infer the type from a local.</p>



<a name="233470744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20inferred%20type%20from%20assert_eq%21%20macro/near/233470744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BaSh <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20inferred.20type.20from.20assert_eq!.20macro.html#233470744">(Apr 07 2021 at 11:27)</a>:</h4>
<p>This might be useful  <a href="https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.type_of">https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.type_of</a></p>
<p><a href="https://willcrichton.net/notes/type-directed-metaprogramming-in-rust/">https://willcrichton.net/notes/type-directed-metaprogramming-in-rust/</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>